package fourzerofour.yangqiang.day02;

import java.util.Arrays;

/**
 * 统计数组nums中，各个数字重复的次数
 */
public class Question1 {
    static final int[] nums = {1, 3, 0, 1, 2, 2, 5, 4};

    public static void main(String[] args) {
        int[] n = {};
        int[] m = {};
        for (int i = 0; i < nums.length; i++) {
                boolean bl = true;
                for (int j = 0; j < m.length; j++) {
                    if (m[j] == nums[i]) {
                        n[j]++;
                        bl = false;
                        break;
                    }
                }
                if(bl){
                    m= Arrays.copyOf(m,m.length+1);
                    n= Arrays.copyOf(n,n.length+1);
                    m[m.length-1] = nums[i];
                    n[n.length-1]++;
                }
        }
        System.out.println("nums数组出现的次数分别：");
        for (int i=0;i<m.length;i++){
            System.out.print(m[i] + "出现" + n[i] + "次");
            System.out.println();
        }
    }
}
